package com.chhuang.ewcrm.interceptor;

import com.chhuang.ewcrm.consts.EwcrmConstants;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author chhuang
 * @create 2020-11-28-8:20
 */
@Configuration
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object obj = request.getSession().getAttribute(EwcrmConstants.SessionConst.SYS_USER);
        if(obj!=null) return true;
        response.sendRedirect("/");
        return false;
    }
}
